package com.example.websocket.mapper;

import com.example.websocket.pojo.po.GroupPo;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Service;

import java.util.HashSet;
import java.util.List;

/**
 * @ author 韩
 * time: 2024/3/24 2:56
 */
@Mapper
public interface GroupMapper {

    @Select("SELECT group_id FROM `member` where member_username = #{username}")
    List<Integer> getOwnGroupList(String username);

    @Select("SELECT * FROM `group` where group_id = #{value}")
    GroupPo getGroupById(Integer value);

    @Insert("INSERT INTO `group`(group_id,group_name,creator) VALUES (#{group_id},#{group_name},#{creator})")
    @Options(useGeneratedKeys = true, keyProperty = "group_id", keyColumn = "group_id")
    void createGroup(GroupPo groupPo);

    @Select("SELECT member_username FROM `group` where group_id = #{groupID}")
    List<String> getMemberById(Integer groupID);

    @Select("SELECT member_username FROM `member` where group_id = #{groupId}")
    HashSet<String> getGroupUserList(String groupId);

    @Insert("INSERT INTO `member` VALUES (NULL, #{groupId}, #{invitedUsername})")
    void invite(Long groupId,String invitedUsername);

    @Select("SELECT member_username FROM `member` WHERE group_id = #{groupId}")
    List<String> selectMemberById(Integer groupId);


//    void selectMemberById(Integer groupId);
}
